import GlobalService from './global.service';
import AgileController from './modules/agile';
import LoginController from './modules/login';
import TesthubController from './modules/testhub';
class PlaywrightTest {
  public loginController: LoginController;
  constructor() {}
  async init() {
    // 注意注册时机
    await new GlobalService().onInit(); // 初始化全局服务
    this.loginController = new LoginController();
    await this.registerTest(); // 注册测试服务
    await this.close(); // 关闭浏览器
  }
  async registerTest() {
    // [所有的页面测试都需要在登录状态下进行]
    await this.loginController.init(); // 注册登录测试服务[必须存在]
    await this.registerTestAddLogin(); // 注册需要在登录状态的测试
  }
  async registerTestAddLogin() {
    const loginStart = await this.loginController.checkLogin()
    if(loginStart) {
      await new AgileController().init()
      await new TesthubController().init()
    }
  }
  async close() {
    const {closeContext, closeBrowser} = globalThis.BrowserBasics
    await closeContext()
    await closeBrowser()
  }
}

(async()=> {
  const playwrightTest = new PlaywrightTest();
  try {
    await playwrightTest.init() ;
  } catch (error) {
    console.log('测试中断', error)
    await playwrightTest.close()
  }
})()


